/*
 * Copyright 2009 Armando Blancas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package taskgraph.tasks;

import java.util.concurrent.Future;

/**
 * Models a full task graph.
 * <p>
 * Creating a graph by composition may go as follows:
 * <pre>
 * Graph graph = new Graph();
 * graph.add(new Task1(...));
 * graph.add(new Task2(...));
 * graph.add(new Task3(...));
 * graph.execute(Wait.NO_WAIT);
 * </pre> 
 * If a particular graph is likely to be reused, client code may
 * write subclasses that will be ready to execute -- there is no
 * need to add them to another composite:
 * <pre>
 * class CommonGraph extends Graph {
 * protected void setup() {
 *     add(new Task1(...));
 *     add(new Task2(...));
 *     add(new Task3(...));
 * }
 * </pre>
 * Clients of {@code CommonGraph} need only to instantiate and execute it:
 * <pre>
 * CommonGraph graph = new CommonGraph();
 * graph.execute(Wait.NO_WAIT);
 * </pre>
 * 
 * @author Armando Blancas
 */
public class Graph extends CompositeTask {

	/**
	 * Default constructor.
	 */
	public Graph() {
		// do nothing
	}

	@Override
	public Future<?> execute(final Wait wait) throws InterruptedException {
		setup();
		return super.execute(wait);
	}

	/**
	 * Optional method.
	 * Client code that builds a graph by composition won't need any setup
	 * --the added tasks make up the setup.
	 * 
	 * <p>Subclasses may redefine this method in order to create a reusable 
	 * graph that is ready to execute. NOTE: Such a graph is not to be added 
	 * to any another.
	 */
	@Override
	protected void setup() {
	}

}
